import request from '@/utils/request'
import { PageDate } from '@/model'
import { ApplicationDTO } from '@/model/efficient/ApplicationDTO'
import { ApplicationServerDTO } from '@/model/efficient/ApplicationServerDTO'
import { ApplicationSetServerDTO } from '@/model/efficient/ApplicationSetServerDTO'
import { GitCommitVO } from '@/model/efficient/GitCommitVO'

/**
 * 获取应用分页
 * @param data
 * @returns
 */
export function applicationPage(params): Promise<PageDate<ApplicationDTO>> {
  return request.get('/api/efficient/application/page', params)
}

export function applicationRemove(id: number) {
  return request.delete(`/api/efficient/application/${id}`)
}

export function applicationSave(data: ApplicationDTO) {
  return request.post('/api/efficient/application', data)
}

export function applicationUpdate(data: ApplicationDTO) {
  return request.put(`/api/efficient/application/${data.id}`, data)
}

export function applicationList():Promise<Array<ApplicationDTO>> {
  return request.get('/api/efficient/application/list')
}

/**
 * 根据应用和环境获取服务器关系
 * @param applicatinId
 * @param environmentId
 */
export function getApplicationServer(applicationId: number, environmentId: number): Promise<Array<ApplicationServerDTO>> {
  return request.get(`/api/efficient/application/getApplicationServer/${applicationId}/${environmentId}`)
}

export function applicationSetServer(applicationServers:Array<ApplicationSetServerDTO>, applicationId:number) {
  return request.post(`/api/efficient/application/setServer/${applicationId}`, {
    applicationServers,
  })
}

export function branchAll(applicationId: number):Promise<Array<string>> {
  return request.get(`/api/efficient/application/branch/${applicationId}`, {})
}
export function commitAll(applicationId: number, branch:string):Promise<Array<GitCommitVO>> {
  return request.get(`/api/efficient/application/commit/${applicationId}`, { branch })
}
